package com.etone.smartAudit.service;

import cn.hutool.core.collection.CollectionUtil;

import com.etone.smartAudit.commService.CommPUumUserinfoService;
import com.etone.smartAudit.domain.PLogVersion;
import com.etone.smartAudit.domain.PUumUserinfo;

import com.etone.smartAudit.vo.PortalBaseVo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author jiayen
 * @since 2021-12-07 11:58:34
 */
@Slf4j
@Service
public class PUumUserinfoService {

    @Autowired
    private PLogVersionService pLogVersionService;

    @Autowired
    private UDSService udsService;

    @Autowired
    private CommPUumUserinfoService commPUumUserinfoService;

    /***
     * 同步人员架构
     */
    public void synUserInfo() throws Exception {
        PLogVersion lastLog = pLogVersionService.getUserLogInfo();
        if (lastLog != null) {
            String logId = lastLog.getLogId();
            //获取异动组织数据
            PortalBaseVo<PUumUserinfo> vo = udsService.bizQueryEmpChgHistory(logId);
            pLogVersionService.updatePersonLog(Boolean.valueOf(vo.getContinuFlag()), PLogVersionService.EMPLOYEE_TYPE);
            List<PUumUserinfo> list = vo.getList();
            if (CollectionUtil.isNotEmpty(list)) {
                list.stream().forEach(userinfo -> {
                    commPUumUserinfoService.addUsrInfo(userinfo);
                });
            }
        }
    }

}
